package com.sun.designpatternsdemo.flyweight.bean

import android.util.Log

/**
 * 版权：xx公司 版权所有
 * @author sun
 * 版本：1.0
 * 创建日期：2021/7/1 13:57
 * 描述：实体
 *
 */
//创建一个接口
interface Shape {
    fun draw()
}

//创建实现接口的实体类。
class Circle(var color: String, var x: Int = 0, var y: Int = 0, var radius: Int = 0) : Shape {
    override fun draw() {
        Log.e(
            "---", "Circle: Draw() [Color : " + color
                    + ", x : " + x + ", y :" + y + ", radius :" + radius
        )
    }
}

//创建一个工厂，生成基于给定信息的实体类的对象
class ShapeFactory {
    companion object {
        val circleMap = HashMap<String, Shape>()
        fun getShape(color: String): Shape {
            var shape = circleMap[color]
            if (shape == null) {
                shape = Circle(color)
                circleMap[color] = shape
                Log.e("getShape", "Creating circle of color : $color")
            }
            return shape
        }
    }
}